<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="app" uri="/WEB-INF/tld/app.tld" %>
<%@ taglib prefix="ct" uri="/WEB-INF/tld/commonTag.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> 
<%@ include file="/WEB-INF/jsp/common/common_header.jsp" %>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>


<script language="javascript">


	function funInsertData(fileId,userId){
		
		var reqDate = $("input[name=deleteDate_"+fileId+"]").val();
		var payProdAmt = $("input[name=payProdAmt_"+fileId+"]").val();
		var payProdFee = $("input[name=payProdFee_"+fileId+"]").val();
		
		if(!payProdAmt){
			alert("지급 금액을 입력하세요");
			$("input[name=payProdAmt_"+fileId+"]").focus();
			return;
		}
		if(payProdAmt<=0){
			alert("지급할 금액이 없습니다");
			$("input[name=payProdAmt_"+fileId+"]").focus();
			return;
		}		
		
		if(!payProdFee){
			alert("지급 수수료을 입력하세요");
			$("input[name=payProdFee_"+fileId+"]").focus();
			return;
		}

		
		var strStatus =reqDate+" 날짜에 "+payProdAmt+" 금액를 정말 지급 하시겠습니까?";
		if (!confirm(strStatus)) {
			return;
		}			
		
		
        var url = "ajaxInsertPay.do";   

        $.ajax({
            type : "POST",
            url : url,
            async : true,
            dataType : "json",
            data : {
            	 reqDate : reqDate
            	,payProdAmt : payProdAmt
            	,payProdFee : payProdFee
            	,userId : userId
            },
            success : function(data) {
            	if(data == 'success'){
            		alert(reqDate+" 날짜 지급 성공");	
            		location.reload(); 
            	}else{
            		alert("지급 실패");
            	}
            },
            error : function(data) {
                alert("통신에러 입니다. 관리자에게 문의 바랍니다.");
               
            }
        }); 
		
	}	
	
    // 검색 버튼 클릭
    function funcSearch() {
        var fm  = document.form;
        $("#page").val(1);
        fm.action = 'payProcess.do';
        fm.submit();
    }
    
    //////////////////////////////////
    //jQuery datepicker Form set
    ///////////////////////////////// 
    $(function() {
        $("#searchStRegDt").koreadate();
        $("#searchEdRegDt").koreadate();

        var totalCnt = ${payProcessList.size()};

        for(var kk=1 ; kk <= totalCnt ; kk++){
        	$("#deleteDate_"+kk).koreadate();	
        	
        }
        
        
        
    });    


    </script>
</head>
<body>
<div class="con_area">
<form id="form" name="form" action="">
<input type="hidden" id="page" name="page" value="${model.page}"/>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
        <td align="left"><h2 class="tit">지급처리  </h2></td>
        <td align="right"><span>이체 관리 > <b>지급처리    </b></span></td>
    </tr>
</table>
    <div style="margin-top:7px"/>
        <table cellpadding="0" cellspacing="0" border="0" class="data_table_01">
            <tr>
                <td class="data_01" style='width:100px; text-align:left;'>&nbsp;검색조건</td>
                <td class="data_02">
                    <select id="searchType" name='searchValueType'>
                        <option value='' <c:out value="${empty model.searchValueType ? 'selected':''}"/>>전체</option>
                        <option value='01' <c:out value="${model.searchValueType eq '01' ? 'selected':''}"/>>가맹점 명</option>
                        <option value='02' <c:out value="${model.searchValueType eq '02' ? 'selected':''}"/>>사업자 번호</option>
                    </select>
                    <input type="text" id="searchValue" name="searchValue" value="${model.searchValue}" maxlength="50" size="20" onkeydown="if(event.keyCode=='13')funcSearch();"/>
                    <input type='button' class='button_63_01' value='검색' onclick='funcSearch();'>
                </td>
            </tr>
        </table>
    <table cellpadding="0" cellspacing="1" border="0" class="data_table_02" style="width:100%;" >
    <colgroup>
        <col width="10%" />
        <col width="25%" />
        <col width="10%" />
        <col width="20%" />
        <col width="15%" />
        <col width="20%" />
    </colgroup>
    <thead>
        <tr>
            <th>번호</th>
            <th>가맹점 명</th>
            <th>요청일</th>
            <th>지급금액</th>
            <th>지급수수료</th>
            <th>등록</th>
        </tr>
    </thead>
    <tbody>
<c:if test='${empty payProcessList}'>    
    <tr>
        <td colspan="6">
            <span style="padding-top:3px;*padding-top:2px;"><strong>조회된 데이터가 존재하지 않습니다.</strong></span>
        </td>
    </tr>
</c:if>
<c:set var="rnum" value="0"/>
<c:if test='${not empty payProcessList}'>
	<c:forEach var="vo" items="${payProcessList}"  varStatus="status">
<c:set var="rnum" value="${status.count+(model.page-1)*10}"/>		
	    <tr onMouseOver="this.style.background='#FFF9E1'" onMouseOut="this.style.background='#FFFFFF'">
	        <td style="text-align:center;">${rnum}</td>
	        <td style="text-align:center;">${vo.storeName}</td>
	        <td style="text-align:center;">
	        	<input type='text' id="deleteDate_${rnum}" name="deleteDate_${rnum}" value="${model.searchEdRegDt}" title="YYYY-MM-DD" style="width: 100px;" maxlength="10" readonly/>
	        </td>
	        <td style="text-align:center;">
			<c:choose>
			    <c:when test="${vo.totalProdAmt < 0}">
					<input type="text" id="payProdAmt_${rnum}" name="payProdAmt_${rnum}" value="<fmt:formatNumber value="0" pattern="#,###" />" maxlength="50" size="20" onkeyup = "js_CheckDigits(this)" onBlur="js_CheckTel(this)"/>
			    </c:when>
			    <c:otherwise>
						<input type="text" id="payProdAmt_${rnum}" name="payProdAmt_${rnum}" value="<fmt:formatNumber value="${vo.totalProdAmt}" pattern="#,###" />" maxlength="50" size="20" onkeyup = "js_CheckDigits(this)" onBlur="js_CheckTel(this)"/> 
			    </c:otherwise>
			</c:choose>		        
	        </td>
	        <td style="text-align:center;">
	        	<input type="text" id="payProdFee_${rnum}" name="payProdFee_${rnum}" value="660" maxlength="50" size="10" onkeyup = "js_CheckDigits(this)" onBlur="js_CheckTel(this)"/>        
	        </td>	        
	        <td style="text-align:center;">
	            <input type="button" class="button_28_02" value="등록" style="width:65px;" onclick="funInsertData('${rnum}','${vo.userId}');" />
	        </td>
	    </tr>
    </c:forEach>
</c:if>
    </tbody>
    </table>
    <br>

    
    <div class="paging_area">
        <ul class="paging_lay">
            <li class="paging_01">
                <ct:paging 
                    requestUrl="payProcess.do?searchStRegDt=${model.searchStRegDt}&searchEdRegDt=${model.searchEdRegDt}&searchValueType=${model.searchValueType}&searchValue=${model.searchValue}" 
                    page="${model.page}" 
                    scale="${model.scale}" 
                    blockScale="10" 
                    total="${model.totalCount}"
                    paramPrefix="model" />
            </li>
        </ul>
    </div>

</form>
</div>
</body>

